package com.miracle.flexAPI.api.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.miracle.flexAPI.api.entity.SysDatasource;
import com.miracle.flexAPI.api.service.SysDatasourceService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * 数据源管理(SysDatasource)表控制层
 *
 * @author miracle
 * @since 2021-08-13 13:33:31
 */
@RestController
@RequestMapping("sysDatasource")
@Api(value = "sysDatasource", tags = {"数据源管理"})
public class SysDatasourceController {

    @Resource
    private SysDatasourceService sysDatasourceService;

    @GetMapping(value = "list")
    @ApiOperation(value = "数据源管理-列表")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "vcSourceCode", value = "数据源编码", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcSourceName", value = "数据源名称", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcUrl", value = "url", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcDriver", value = "driver", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcUser", value = "用户", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcPwd", value = "密码", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "fMaxactive", value = "最大连接数", defaultValue = "", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "")
    })
    public AjaxResult list(@ApiIgnore SysDatasource dto) {
        return sysDatasourceService.list(dto);
    }


    @GetMapping(value = "add")
    @ApiOperation(value = "数据源管理-添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vcSourceCode", value = "数据源编码", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcSourceName", value = "数据源名称", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcUrl", value = "url", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcDriver", value = "driver", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcUser", value = "用户", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcPwd", value = "密码", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "fMaxactive", value = "最大连接数", defaultValue = "", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "")
    })
    public AjaxResult add(@ApiIgnore SysDatasource model) {
        return sysDatasourceService.add(model);
    }


    @GetMapping(value = "edit")
    @ApiOperation(value = "数据源管理-编辑")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vcSourceCode", value = "数据源编码", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcSourceName", value = "数据源名称", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcUrl", value = "url", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcDriver", value = "driver", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcUser", value = "用户", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "vcPwd", value = "密码", defaultValue = "", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "fMaxactive", value = "最大连接数", defaultValue = "", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "")
    })
    public AjaxResult edit(@ApiIgnore SysDatasource model) {
        return sysDatasourceService.edit(model);
    }


    @GetMapping(value = "delete")
    @ApiOperation(value = "数据源管理-删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vcSourceCode", value = "数据源编码", defaultValue = "", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "")
    })
    public AjaxResult delete(@ApiIgnore SysDatasource dto) {
        return sysDatasourceService.delete(dto);
    }

    @GetMapping(value = "load")
    @ApiOperation(value = "数据源管理-装载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vcSourceCode", value = "数据源编码", defaultValue = "", dataType = "String", paramType = "query"),
    })
    public AjaxResult load(@ApiIgnore SysDatasource dto) {
        return sysDatasourceService.loadByCode(dto);
    }

    @GetMapping(value = "unload")
    @ApiOperation(value = "数据源管理-卸载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vcSourceCode", value = "数据源编码", defaultValue = "", dataType = "String", paramType = "query"),
    })
    public AjaxResult unload(@ApiIgnore SysDatasource dto) {
        return sysDatasourceService.unloadByCode(dto);
    }

}
